package com.a.lib_route

import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.service.SerializationService
import com.a.lib_utils.GsonUtil
import java.lang.reflect.Type

@Route(path = "/service/json_serialization")
class ARouterJSONServiceImpl : SerializationService {

    override fun init(context: Context?) {
    }

    override fun <T : Any> json2Object(
        input: String?,
        clazz: Class<T>?
    ): T? {
        return parseObject(input, clazz)
    }

    override fun object2Json(instance: Any?): String? {
        return GsonUtil.jsonFactory.toJson(instance)
    }

    override fun <T : Any> parseObject(
        input: String?,
        clazz: Type?
    ): T? {
        return GsonUtil.jsonFactory.fromJson(input, clazz)
    }
}